TypeScript: Modern JavaScript Development by Remo H. Jansen & Vilic Vane & Ivo Gabe de Wolff

TypeScript: Modern JavaScript Development by Remo H. Jansen & Vilic Vane & Ivo Gabe de Wolff

Author:Remo H. Jansen & Vilic Vane & Ivo Gabe de Wolff
Language: eng
Format: mobi
Publisher: Packt Publishing
Published: 2016-12-21T23:00:00+00:00


set<T, TExtra extends ServerDataItemExtra>(

id: string,

item: ServerDataItem<T> & Textra

): void {

this.items[id] = item;

}

getAll<T, TExtra extends ServerDataItemExtra>():

(ServerDataItem<T> & TExtra)[] {

let items = this.items;

return Object

.keys(items)

.map(id => items[id] as ServerDataItem<T> & TExtra);

}

You may have noticed from the interfaces and generics that I've also torn down ServerDataItem into intersection types of the common part and extras.

Summary

In this chapter, we've been part of the evolution of a simplified yet reality-related project. Starting with a simple code base that couldn't be wrong, we added a lot of features and experienced the process of putting acceptable changes together and making the whole thing a mess.

We were always trying to write readable code by either naming things nicely or adding semantically necessary redundancies, but that won't help much as the complexity grows.

During the process, we've learned how offline synchronizing works. And with the help of the most common design patterns, such as the Strategy Pattern, we managed to split the project into small and controllable parts.

In the upcoming chapters, we'll catalog more useful design patterns with code examples in TypeScript, and try to apply those design patterns to specific issues.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.